<template>
  <div class="information">
    <el-form :model="data.form" ref="informationForm"  label-width="120px" >
      <el-form-item label="用户名" prop="" >
        <el-input v-model="username" disabled></el-input>
      </el-form-item>
      <el-form-item label="邮箱" prop="">
        <el-input v-model="email"></el-input>
      </el-form-item>
      <el-form-item label="手机号" prop="">
        <el-input v-model="mobile"></el-input>
      </el-form-item>
      <el-form-item label="头像" prop="">
        <el-upload
          class="avatar-uploader"
          action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload"
        >
          <img v-if="imageUrl" :src="imageUrl" class="avatar" />
          <el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
        </el-upload>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" >保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts" setup>
import { reactive, toRefs, onMounted } from 'vue';
import { getCode } from '@a/code';

const data = reactive({
  form: {
    userId: '',
    username: 'zyy',
    email: '',
    mobile: '',
    avatar: ''
  }
})
const { userId, username, email, mobile, avatar } = toRefs(data.form);
onMounted(() => {
  getCode(data.form.username)
  .then(response => {
    console.log(response);
  })
  .catch(error => {
    console.log(error);
  })
})

</script>

<style scoped>
  .information {
    width: 400px;
    margin: 0 auto;
    margin-top: 50px;
    padding: 10px;
    background-color: white;
    border-radius: 10px;
  }
  .information .el-form {
    margin-top: 30px;
    padding-right: 70px;
  }
  .el-button {
    width: 100px;
    margin: 0 auto;
  }

  /* 图片上传框样式 */
  .avatar-uploader .avatar {
  width: 178px;
  height: 178px;
  display: block;
}

  
</style>


<style>
.avatar-uploader .el-upload {
    border: 1px dashed var(--el-border-color);
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: var(--el-transition-duration-fast);
  }

  .avatar-uploader .el-upload:hover {
    border-color: var(--el-color-primary);
  }

  .el-icon.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    text-align: center;
  }
</style>